package org.xiaov.lunasql.engine.transform.interval;

import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntervalExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntervalUnit;

/**
 * <p>
 * QuarterIntervalHandler 周日转换为日
 * </p>
 *
 * @author lzq
 * @since 2024/12/24 16:25
 */
public class Week2DayIntervalHandler implements IntervalHandler {
    @Override
    public void interval(SQLIntervalExpr x) {
        x.setUnit(SQLIntervalUnit.DAY);
        if (x.getValue() instanceof SQLIntegerExpr integerExpr) {
            int day = integerExpr.getNumber().intValue() * 7;
            x.setValue(new SQLCharExpr(day + ""));
        } else if (x.getValue() instanceof SQLCharExpr charExpr) {
            int day = Integer.parseInt(charExpr.getText()) * 7;
            x.setValue(new SQLCharExpr(day + ""));
        }
    }
}
